using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsApplication4
{
    public partial class AddTarget : Form
    {
        public AddTarget()
        {
            InitializeComponent();
        }

        public AddTarget(Village vill)
        {
            InitializeComponent();

            this.villageLookup1.SelectedVillage =vill;
            villageLookup1_SelectedVillageChangeFoundEvent(vill);
        }

        Target targetToModify;
        public AddTarget(Target target)
        {
            InitializeComponent();

            this.Text = "Modify Target";
            this.btnOK.Text = "Modify this target";
            this.villageLookup1.SelectedVillage = target.TargetVillage;
            villageLookup1_SelectedVillageChangeFoundEvent(target.TargetVillage);
            this.txtDescription.Text = target.Description;
            btnOK.Enabled = true;
            this.targetToModify = target;
        }


        private void AddTarget_Load(object sender, EventArgs e)
        {
            villageLookup1.SelectedVillageChangeFoundEvent += new VillageLookup.SelectedVillageChangeDelegate(villageLookup1_SelectedVillageChangeFoundEvent);
        }
        public Village selectedVillage = null;

        void villageLookup1_SelectedVillageChangeFoundEvent(Village vil)
        {
            selectedVillage = vil;

            if (vil == null)
            {
                btnOK.Enabled = false;
            }
            else
            {
                btnOK.Enabled = true;
            }
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            if (targetToModify != null)
            {
                targetToModify.TargetVillage = selectedVillage;
                targetToModify.Description = txtDescription.Text;
            }

            this.DialogResult = DialogResult.OK;
            this.Close();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
            this.Close();
        }

        private void AddTarget_FormClosing(object sender, FormClosingEventArgs e)
        {
            WindowsApplication4.Properties.Settings.Default.Save();
        }
    }
}